$(function() {
				var $form_div = $("#monthNursing_form div");
				winResize($form_div);
				$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
					winResize($form_div);
				});
				
				loadTable();
				
})


var $form = $('#monthNursing_form');
function  loadTable()
{	
	var columnsAll = new Array();
	columnsAll.push({field:'cusids',title:'ids',rowspan:2,hidden:true});
	
	columnsAll.push({field:'cusname',title:'姓名',width:50,align:'center',rowspan:2,
		formatter: function(value,row,index)
		{	var ids = row.cusids;
			var noDelWeight=parseFloat(row.lastweight)-parseFloat(row.stantardweight);
			
			if(value==null)
			{
				return  row.cusname=" ";
			}
			else
			{
				if(noDelWeight<=0)
				{
					return '<a href="#" style="color: green;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
				}else
				{
					return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
				}
				
			}
			
		}
	});
	
	columnsAll.push({field:'intostoredate',title:'进店日期',width:80,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'initialweight',title:'最初体重',width:50,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'stantardweight',title:'标准体重',width:50,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'weightloss',title:'应减斤数',width:50,align:'center',rowspan:2,sortable:true});
	
	
	columnsAll.push({field:'lasttostore',title:'最后到店时间',width:80,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'lastweight',title:'最后体重',width:50,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'delweightnum',title:'减重<br/>次数',width:30,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'haveDelWeight',title:'已减斤数',width:50,align:'center',rowspan:2,
		formatter: function(value,row,index)
		{	
			var haveDelWeight=parseFloat(row.initialweight)-parseFloat(row.lastweight);
			return  row.haveDelWeight=haveDelWeight.toFixed(2);
		}
	});
	columnsAll.push({field:'noDelWeight',title:'未减斤数',width:50,align:'center',rowspan:2,
		formatter: function(value,row,index)
		{	
			var noDelWeight=parseFloat(row.lastweight)-parseFloat(row.stantardweight);
			if(noDelWeight>0){return  row.noDelWeight=noDelWeight.toFixed(2);}
			else{return  row.noDelWeight="0";}
		}
	});
	columnsAll.push({field:'monthAverage',title:'月均减重斤数',width:50,align:'center',rowspan:2,sortable:true,
		formatter: function(value,row,index)
		{	
			var haveDelWeight=parseFloat(row.initialweight)-parseFloat(row.lastweight);
			return  row.haveDelWeight=(haveDelWeight/12).toFixed(2);
		}
	});
	columnsAll.push({field:'jzxg',title:'减重效果',width:80,align:'center',rowspan:2,
		formatter: function(value,row,index)
		{	
			var haveDelWeight=parseFloat(row.initialweight)-parseFloat(row.lastweight);
			var haveDelWeight=(haveDelWeight/parseFloat(row.weightloss)*100).toFixed(2);
			if(parseFloat(row.weightloss) == '0'  ){
				return '';
			}else{
				if(haveDelWeight<30){
					return  "<span  style='color:red'>" +haveDelWeight + "%"+ "<span>"
				}else if(haveDelWeight>=30&&haveDelWeight<40){
					return  "<span  style='color:pink'>" +haveDelWeight + "%"+ "<span>"
				}
				else if(haveDelWeight>=40&&haveDelWeight<50){
					return  "<span  style='color:purple'>" +haveDelWeight + "%"+ "<span>"
				}
				else if(haveDelWeight>=50&&haveDelWeight<60){
					return  "<span  style='color:#90dff9'>" +haveDelWeight + "%"+ "<span>"
				}
				else if(haveDelWeight>=60&&haveDelWeight<70){
					return  "<span  style='color:blue'>" +haveDelWeight + "%"+ "<span>"
				}
				else if(haveDelWeight>=70&&haveDelWeight<80){
					return  "<span  style='color:#90f977'>" +haveDelWeight + "%"+ "<span>"
				}
				else if(haveDelWeight>=80){
					return  "<span  style='color:green'>" +haveDelWeight + "%"+ "<span>"
				}
				
			}
			
			
		}
	});
	for(var n=1;n<13;n++)
	{
		columnsAll.push({field:'month_'+n,title:n+"月",align:'center',colspan:2});
	}
	columnsAll.push({field:'weightoflastmonth',title:'收取疗程数',width:100,align:'center',rowspan:2,sortable:true});
	columnsAll.push({field:'organname',title:'机构名称',width:100,align:'center',rowspan:2});
	//columnsAll.push({field:'cusphone',title:'手机',width:100,align:'center',rowspan:2});
	columnsAll.push({field:'cushybh',title:'会员编号',width:100,align:'center',rowspan:2,sortable:true});
/*	columnsAll.push({field:'isdb',title:'是否达到标体',width:100,align:'center',rowspan:2,
		formatter: function(value,row,index)
		{	
			var noDelWeight=parseFloat(row.lastweight)-parseFloat(row.stantardweight);
			if(noDelWeight<=0)
			{
				return '<span style="color:#ff954e;">是</span>';
			}else
			{
				return "否";
			}
			
		}
	});*/
	
	var columnsAll1 = new Array();
	for(var m=1;m<13;m++)
	{
		if(m<10){
			m = "0"+m;
		}
		columnsAll1.push({field:'lastweight'+m,title:'最后体重',align:'center'});
		//columnsAll1.push({field:'month_'+m+'_lastweight',title:'最后体重',align:'center'});
		columnsAll1.push({field:'ddcount'+m,title:'到店次数',align:'center'});
	}
	
	
	
	$('#monthNursing_datagrid').datagrid({
		cls: "theme-datagrid",
		  singleSelect:true,  
		  rownumbers: true,
		  toolbar: '#tb',
		  collapsible: true,
		  columns:[columnsAll,columnsAll1],
		  url: "monthNursing/getMonthNursing",
		  queryParams: sy.serializeObject($form),
		  pagination: true,
		  pageSize: 10,
		  method: 'post',
		  remoteSort:false,
		  multiSort:true
		
	});

}
function searchFrom(){
	loadTable();
}
